<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>退款申请API测试</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        .test-section {
            margin-bottom: 30px;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 8px;
        }
        .test-section h3 {
            margin-top: 0;
            color: #333;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input, select {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        button {
            background-color: #1890ff;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            margin-right: 10px;
        }
        button:hover {
            background-color: #40a9ff;
        }
        .result {
            margin-top: 15px;
            padding: 15px;
            background-color: #f8f9fa;
            border-radius: 4px;
            white-space: pre-wrap;
            font-family: monospace;
            max-height: 400px;
            overflow-y: auto;
        }
        .error {
            background-color: #f8d7da;
            color: #721c24;
        }
        .success {
            background-color: #d4edda;
            color: #155724;
        }
    </style>
</head>
<body>
    <h1>退款申请API测试</h1>
    
    <div class="test-section">
        <h3>获取退款申请列表</h3>
        <div class="form-group">
            <label>患者信息（姓名或手机号）：</label>
            <input type="text" id="patientInfo" placeholder="请输入患者姓名或手机号">
        </div>
        <div class="form-group">
            <label>申请开始时间：</label>
            <input type="datetime-local" id="applyStartTime">
        </div>
        <div class="form-group">
            <label>申请结束时间：</label>
            <input type="datetime-local" id="applyEndTime">
        </div>
        <div class="form-group">
            <label>状态：</label>
            <select id="status">
                <option value="">全部</option>
                <option value="0">待处理</option>
                <option value="1">已处理</option>
                <option value="2">已拒绝</option>
            </select>
        </div>
        <div class="form-group">
            <label>页码：</label>
            <input type="number" id="pageIndex" value="1" min="1">
        </div>
        <div class="form-group">
            <label>每页大小：</label>
            <input type="number" id="pageSize" value="10" min="1" max="100">
        </div>
        <button onclick="testGetList()">获取列表</button>
        <div id="listResult" class="result"></div>
    </div>
    
    <div class="test-section">
        <h3>获取退款申请详情</h3>
        <div class="form-group">
            <label>申请ID：</label>
            <input type="number" id="detailId" placeholder="请输入申请ID">
        </div>
        <button onclick="testGetDetail()">获取详情</button>
        <div id="detailResult" class="result"></div>
    </div>
    
    <div class="test-section">
        <h3>获取统计信息</h3>
        <button onclick="testGetStatistics()">获取统计</button>
        <div id="statisticsResult" class="result"></div>
    </div>

    <script>
        const API_BASE = 'http://localhost:5242/api';
        
        async function makeRequest(url, options = {}) {
            try {
                const response = await fetch(url, {
                    headers: {
                        'Content-Type': 'application/json',
                        ...options.headers
                    },
                    ...options
                });
                
                const data = await response.json();
                return { success: true, data, status: response.status };
            } catch (error) {
                return { success: false, error: error.message };
            }
        }
        
        function displayResult(elementId, result) {
            const element = document.getElementById(elementId);
            if (result.success) {
                element.className = 'result success';
                element.textContent = JSON.stringify(result.data, null, 2);
            } else {
                element.className = 'result error';
                element.textContent = `错误: ${result.error}`;
            }
        }
        
        async function testGetList() {
            const params = new URLSearchParams();
            
            const patientInfo = document.getElementById('patientInfo').value;
            const applyStartTime = document.getElementById('applyStartTime').value;
            const applyEndTime = document.getElementById('applyEndTime').value;
            const status = document.getElementById('status').value;
            const pageIndex = document.getElementById('pageIndex').value;
            const pageSize = document.getElementById('pageSize').value;
            
            if (patientInfo) params.append('patientInfo', patientInfo);
            if (applyStartTime) params.append('applyStartTime', applyStartTime);
            if (applyEndTime) params.append('applyEndTime', applyEndTime);
            if (status) params.append('status', status);
            params.append('pageIndex', pageIndex);
            params.append('pageSize', pageSize);
            
            const url = `${API_BASE}/RefundApplication/list?${params.toString()}`;
            const result = await makeRequest(url);
            displayResult('listResult', result);
        }
        
        async function testGetDetail() {
            const id = document.getElementById('detailId').value;
            if (!id) {
                displayResult('detailResult', { success: false, error: '请输入申请ID' });
                return;
            }
            
            const url = `${API_BASE}/RefundApplication/detail/${id}`;
            const result = await makeRequest(url);
            displayResult('detailResult', result);
        }
        
        async function testGetStatistics() {
            const url = `${API_BASE}/RefundApplication/statistics`;
            const result = await makeRequest(url);
            displayResult('statisticsResult', result);
        }
    </script>
</body>
</html> 